const course = {
    state: {
        page: 0,
        limit: 10,
        list: [],//课程列表
        classify: [],//分类数据
        gradeIndex: 0,//分类年级id
        subjectIndex: 0,//分类学科id
        order_by: 0,//排序
        course_type: -1,//课程类型
        show: false,
    },
    mutations: {
        //页数增加
        pj(state) {
            state.page++;

            this.commit('getBasis')
        },
        //拿取课堂列表     //拿取默认课堂列表
        getBasis(state) {
            if (state.page === 1) {
                state.list = [];
            }
            this.$http.courseBasis({
                page: state.page,
                limit: state.limit,
                attr_val_id: `${state.gradeIndex === 0 ? '' : state.gradeIndex}${state.subjectIndex === 0 ? '' : ',' + state.subjectIndex}`,
                order_by: `${state.order_by === 0 ? '' : state.order_by}`,
                course_type: `${(state.course_type === -1 ? '' : state.course_type) === 1 ? 0 : (state.course_type === -1 ? '' : state.course_type)}`,
                is_vip: `${state.course_type === 0 ? 1 : ''}`
            }).then(res => {
                if (res.data.data.list.length === 0) {
                    state.show = true;
                }

                state.list = [...state.list, ...res.data.data.list]

                if (state.page === 1) {
                    window.scrollTo(0, 0);
                }
            })
        },
        GETBASISS(state) {
            if (state.page === 0) {
                state.page = 1
            } else if (state.page >= 1) {
                return false;
            }


            this.commit('getBasis')
        },
        //加载更多
        // pjGet(state) {
        //     this.$http.courseBasis({
        //         page: state.page,
        //         limit: state.limit,
        //         attr_val_id: `${state.gradeIndex === 0 ? '' : state.gradeIndex}${state.subjectIndex === 0 ? '' : ',' + state.subjectIndex}`,
        //         order_by: `${state.order_by === 0 ? '' : state.order_by}`,
        //         course_type: `${(state.course_type === -1 ? '' : state.course_type) === 1 ? 0 : (state.course_type === -1 ? '' : state.course_type)}`,
        //         is_vip: `${state.course_type === 0 ? 1 : ''}`
        //     }).then(res => {
        //         if (res.data.data.list.length === 0) {
        //             state.show = true;
        //         }
        //         state.list = [...state.list, ...res.data.data.list]
        //     })
        // },
        //获取到分类数据
        Classify(state, data) {
            if (state.classify.length > 0) {
                return
            }
            this.$http.Classify().then(res => {
                state.classify = res.data.data.attrclassify;
            })
        },
        //重置筛选
        reset(state, data) {//选择分类id,重置分类
            if (!data) {
                state.gradeIndex = 0;
                state.subjectIndex = 0
                state.page = 1
                state.order_by = 0//排序
                state.course_type = -1

                this.commit('getBasis')
            } else {
                state[data.name] = data.id;
            }
        },
        //排序选择
        Sort(state, index) {
            state.order_by = index
            state.page = 1
            this.commit('getBasis')
        },
        //课程类型筛选选择
        gradeCheck(state, index) {
            state.course_type = index
            state.page = 1

            this.commit('getBasis')
        },

    },
    actions: {
        //拿取课堂分类
        Classify(context) {
            context.commit('Classify')
            // this.$http.Classify({}).then(res => {
            //     context.commit('Classify', res.data.data.attrclassify)
            // })
        }
    },
    module: {}
};

export default course;